n_data = size(tau_ideal,2);
nb=size(tau_ideal,1);
n_data = 3000


cvx_begin sdp
    cvx_solver Mosek
    cvx_precision high
    variable inertial_pi(nb*10)
    expressions inertial_sdp_matrix(4,4,nb) semidefinite  symmetric
    expressions mj(nb)
    expressions lj(3,1,nb)
    expressions Ij(3,3,nb)
    expression error_norm1(n_data,1)

    tau = tau_ideal;

    for i=1:n_data
        error_norm1(i) = norm(K(:,:,i)*inertial_pi-tau(:,i),2);
    end
%     error_norm1 = error_norm1/n_data;
    minimize sum(error_norm1) 
    for j = 1:nb
        mj(j) = inertial_pi((j-1)*10+1,1);
        lj(:,:,j) = inertial_pi((j-1)*10+2:(j-1)*10+4,1);
        Ij(:,:,j) = [inertial_pi((j-1)*10+1) inertial_pi((j-1)*10+2) inertial_pi((j-1)*10+3);
                    inertial_pi((j-1)*10+2) inertial_pi((j-1)*10+4) inertial_pi((j-1)*10+5);
                    inertial_pi((j-1)*10+3) inertial_pi((j-1)*10+5) inertial_pi((j-1)*10+6)];
       
        inertial_sdp_matrix(4,4,j) = mj(j);
        inertial_sdp_matrix(1:3,1:3,j) = 0.5*trace(Ij(:,:,j))*eye(3) - Ij(:,:,j);
        inertial_sdp_matrix(4,1:3,j) =  lj(:,:,j)';
        inertial_sdp_matrix(1:3,4,j) =  lj(:,:,j);
    end

    subject to
%         inertial_sdp_matrix(1:3,1:3,1)>=0;
%         inertial_sdp_matrix(1:3,1:3,2)>=0;
%         inertial_sdp_matrix(1:3,1:3,3)>=0;
%         inertial_sdp_matrix(4,4,1)>0;
%         inertial_sdp_matrix(4,4,2)>0;
%         inertial_sdp_matrix(4,4,3)>0;
        inertial_sdp_matrix(:,:,1) >= 0;
        inertial_sdp_matrix(:,:,2) >= 0;
        inertial_sdp_matrix(:,:,3) >= 0;
%         inertial_sdp_matrix(:,:,2) >= 0;
%         inertial_sdp_matrix(:,:,3) >= 0;

cvx_end